<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
		<title>导入企业</title>
		<script type="text/javascript" src="js/common.js"></script>
	</head>
	<body>
		<div id="frame_child">
			<div class="accounttitle">
				<p>企业>导入企业</p>
            </div>

			<form class="form-horizontal" role="form" style="width: 500px;margin: 50px auto;">
                <div class="form-group">
                  <label for="file" class="col-sm-2 control-label">选择文件</label>
                  <div class="col-sm-10">
                    <input type="file" class="form-control" id="excel-file" name="file" placeholder="请选择要导入excel文件" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
                  </div>
                </div>

                <div class="form-group">
                  <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" class="btn btn-primary excel-import">导入</button>
                  </div>
                </div>
            </form>
        </div>

        <div class="modal fade" id="loadingModal" backdrop="static" keyboard="false">
            　　
            <div style="width: 300px;height:100px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px">
                　　　　
                <div class="progress progress-striped active"
                    style="margin-bottom: 0;height:50px; text-align:center;line-height: 50px;font-size:14px;">
                    数据导入中,请稍候......　　　　
                </div>
                　　
            </div>
        </div>
        <script type="text/javascript">
			
            $(document).ready(function(){
                $('.excel-import').click(function(){
                    var file = $('#excel-file')[0].files[0]
                    if (file.name.indexOf('.xlsx') == -1) {
                        showErr('只允许导入.xlsx文件')
                        return
                    }
                    if (file !== undefined) {
                        var formData = new FormData()
                        formData.append("file",file)
                        showLoading()
                        $.ajax({
                            url: service_url + '/a/zhiku/zkEntInfo/importExcel',
                            data: formData,
                            type: 'GET',
                            headers: {
                                "Authorization": $.cookie("AuthorizationAdmin")
                            },
                            xhrFields: {
                                withCredentials: true
                            },
                            crossDomain: true,
                            contentType: false, // 不设置内容类型  
                            dataType: 'text',
                            jsonpCallback:"success_jsonpCallback",  
                            processData: false, // 告诉jQuery不要去处理发送的数据
                            success: function(data) {
                                // console.log(data)
                                hideLoading()
                                if (data.status === '00') {
                                    top.alert("导入成功",'', function() {
                                        $('#excel-file').val('')
                                    },{type: 'success'});
                                } else {
                                    showErr(data.msg || '导入失败')
                                } 
                            },
                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                hideLoading()
                                console.log(XMLHttpRequest, textStatus, errorThrown)
                            }
                        })
                    } else {
                        showErr("请先选择要上传的excel文件")
                    }
                })
            })

        </script>
	</body>

</html>